<?php

namespace app\api\controller;
use app\common\service\QiniuService;

/**
 * 上传模块API
 */
class Upload extends Base
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * showdoc
     * @catalog CRM接口/文件相关
     * @title 上传
     * @description
     * @method POST
     * @url /api/Upload/uploadFile
     * @param file 必选 string 文件
     * @return
     * @remark
     * @number 0
     * @author lcx
     * @date 2019-04-28
     */
    public function uploadFile()
    {
        $upload = new QiniuService();
        $result = $upload->up2QiNiuYun('file');
        if (!is_array($result)) {
            $data['all_url'] = config('api.qi_niu_url') . $result;
            $data['url'] = $result;
            returnJson(1000, "上传成功", $data);
        }
        returnJson(-1000, "上传失败");
    }


    // 富文本图片--规格图片 -- 上传,注意返回code
    public function uploadRichTextFile()
    {
        $upload = new QiniuService();
        $result = $upload->up2QiNiuYun('file');
        if (!is_array($result)) {
            $data['src'] = config('api.qi_niu_url') . $result;
            $data['title'] = $result;
            returnJson(0, "上传成功", $data);
        }
        returnJson(1, "上传失败");
    }


}
